#ifndef _TIMER_FUNC_H__
#define _TIMER_FUNC_H__

#include "../complib/libtsmp/include/tsmp_api.h"
#include "../complib/libtsmp/include/tsmp_type.h"
#include "../complib/libtsninsight/include/tsninsight.h"

#define TABLE_QUERY_TIME ((u64)300) // 表项查询时间
#define PORT_QUERY_TIME ((u64)300)  // 端口查询时间

#define IP_HEADER_LEN 20 /*IP头报文长度*/
#define UDP_HEADER_LEN 8 /*UDP头报文长度*/

/*ether头部（无vlan）*/
typedef struct
{
  unsigned char dmac[6];   // dmac
  unsigned char smac[6];   // 源mac
  unsigned short eth_type; /* 以太网类型 */
} __attribute__((packed)) igmp_eth_header;

/*IP报文头部*/
typedef struct
{
  unsigned char ver;     /* 版本   */
  unsigned char tos;     /* 版本   */
  unsigned short ip_len; // IP报文的总长度
  unsigned short number; // 序列号
  unsigned short flag;
  unsigned char ttl;        // TTL字段
  unsigned char protocol;   // IP协议
  unsigned short check_sum; // 校验和
  unsigned char src_ip[4];
  unsigned char dst_ip[4];
} __attribute__((packed)) igmp_ip_header;

/*igmp报文头部*/
typedef struct
{
  unsigned char type;
  unsigned char max_response_time;
  unsigned short check_sum;
  unsigned char multicast_addr[4];
} __attribute__((packed)) igmp_igmp_header;

// igmpV3报文头
typedef struct
{
  unsigned char record_type;
  unsigned char data_len;
  unsigned short number_of_sources;
  unsigned char V3_multicast_addr[4];
} __attribute__((packed)) igmp_V3_header;

// igmp报文
typedef struct
{
  igmp_eth_header eth_header;   /*以太网头*/
  igmp_ip_header ip_header;     /* ip头 */
  igmp_igmp_header igmp_header; /* igmp头 */
} __attribute__((packed)) igmp_pkt;

int timer_func(u64 cur_time_count_ns);
int igmp_special_pkt_create(u8 *ip);
u64 get_cur_nano_sec();
u64 get_diff(u64 cur_time, u64 start_time);
void igmp_free();

#endif